package config

import (
	"github.com/hwcer/cosgo/random"
	"github.com/hwcer/yyds"
)

const (
	PendantGroupProcessName = "PendantGroupProcess"
)

// 道具类型分析
func init() {
	yyds.Config.Register(&unit{})
}

func GetPendantGroupRandom(id int32) *random.Random {
	i := yyds.Config.Process.Get(PendantGroupProcessName)
	if i == nil {
		return nil
	}
	g, ok := i.(map[int32]*random.Random)
	if !ok {
		return nil
	}
	return g[id]
}

type unit struct {
	HandleDefault
}

func (this *unit) Handle(c *yyds.CS, i any) {
	data := i.(*output)
	d := map[int32]*random.Random{}
	for _, v := range data.PendantGroup {
		r := d[v.PendantGroup]
		if r == nil {
			r = &random.Random{}
			d[v.PendantGroup] = r
		}
		r.Add(v.Id, v.Val)
	}
	c.Process.Set(PendantGroupProcessName, d)
	return
}
